package br.com.hd.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.faces.context.FacesContext;

import br.com.hd.dao.DAO;
import br.com.hd.entity.Status;

public class StatusController {

	private Status status;
	private List<Status> statusList = new ArrayList<Status>();

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public List<Status> getStatusList() {
		return statusList;
	}

	public void setStatusList(List<Status> statusList) {
		this.statusList = statusList;
	}

	public void cadastrar() throws IOException {
		status = new Status();
		FacesContext.getCurrentInstance().getExternalContext()
				.redirect("cadastrarStatus.jsp");
	}

	@SuppressWarnings("unchecked")
	public List<Status> listar() throws IOException {
		status = new Status();
		statusList = new ArrayList<Status>();
		statusList = DAO.getInstance().list(Status.class);
		FacesContext.getCurrentInstance().getExternalContext()
				.redirect("listarStatus.jsp");
		return statusList;
	}

	public void salvar() throws Exception {
		DAO.getInstance().saveOrUpdate(status);
		status = new Status();
	}
	
	
	public Status editar() throws IOException {
		FacesContext context = FacesContext.getCurrentInstance();
		status = (Status) context.getExternalContext().getRequestMap()
				.get("list");
		FacesContext.getCurrentInstance().getExternalContext()
				.redirect("cadastrarStatus.jsp");
		return status;
	}
}
